package logic

import (
	"context"
	"house_srv/model/mysql"

	"house_srv/house"
	"house_srv/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type HouseListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewHouseListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *HouseListLogic {
	return &HouseListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *HouseListLogic) HouseList(in *house.HouseListRequest) (*house.HouseListResponse, error) {
	// todo: add your logic here and delete this line
	var houses []mysql.House
	mysql.DB.Debug().Find(&houses)
	var list []*house.HouseList
	for _, m := range houses {
		ls := house.HouseList{
			Name:    m.Name,
			Area:    float32(m.Area),
			Price:   float32(m.Price),
			Address: m.Address,
		}
		list = append(list, &ls)
	}
	return &house.HouseListResponse{List: list}, nil
}
